class AsyncParralleHook { // 钩子 是同步的

  constructor(args) { // args => ['name']
    this.tasks = [];

  }

  tapPromise(name, task) {// 事件名字 事件方法
    this.tasks.push(task);
  }

  promise(...args) {
    let tasks = this.tasks.map(task => task(...args));
    return Promise.all(tasks);
  }

}

let hook = new AsyncParralleHook(['name']);
hook.tapPromise('react', (name) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log('react', name);
      resolve();
    }, 1000);
  });
});

hook.tapPromise('vue', (name) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log('vue', name);
      resolve();
    }, 1000);
  });
});


hook.promise('gzw')
  .then(() => {
    console.log('end');
  });

// AsyncParralleBailHook() 带保险的 异步并发钩子
